package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.manager.member.entities.models.MemberMaterialPig;
import com.smart.manager.member.entities.models.MemberMaterialProps;
import com.smart.manager.work.entities.models.PigOrder;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.PigBody;
import com.smart.wap.bodys.ShopResult;
import com.smart.wap.responsive.PigResponsive;
import com.smart.wap.service.PigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author leo
 * @date 2023/10/05
 */
@Api(tags = "WTB-移动端-猪猪操作")
@RestController
@RequestMapping(SmartConstant.WAP_API_PREFIX + "app/pig")
@RequiredArgsConstructor
@Log4j2
public class PigController {

    private final PigService pigService;

    /**
     * @param body
     * @return {@link AjaxResult}<{@link String}>
     */
    @ApiOperation(value = "使用零食")
    @PostMapping(value = "getFeeding")
    @SaCheckLogin(type = MemberStp.TYPE)
    @ApiOperationSupport(order = 3)
    public AjaxResult<Map<String,Object>> feeding(@RequestBody @Validated PigBody.EditBody body) {
        Long memberId = MemberAcl.getLoginId();
        Map<String,Object> feeding = pigService.feeding(memberId, body);
        return AjaxResult.data(feeding);
    }


    /**
     * @param body
     * @return {@link AjaxResult}<{@link String}>
     */
    @ApiOperation(value = "使用CDK")
    @PostMapping(value = "useCdk")
    @SaCheckLogin(type = MemberStp.TYPE)
    @ApiOperationSupport(order = 3)
    public AjaxResult<ShopResult.Rem> useCdk(@RequestBody @Validated PigBody.CDKBody body) {
        ShopResult.Rem rem = pigService.useCdk(body.getCdk());
        return AjaxResult.data(rem);
    }

    @ApiOperation(value = "查询背包/零食/道具")
    @GetMapping(value = "getPropsList")
    @SaCheckLogin(type = MemberStp.TYPE)
    @ApiOperationSupport(order = 2)
    public AjaxResult<List<MemberMaterialProps>> getPropsList() {
        Long memberId = MemberAcl.getLoginId();
        List<MemberMaterialProps> result = pigService.getPropsList(memberId);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "使用道具/零食/服务")
    @PostMapping(value = "setUse")
    @SaCheckLogin(type = MemberStp.TYPE)
    @ApiOperationSupport(order = 3)
    public AjaxResult<Map<String,Object>> setUse(@RequestBody @Validated PigBody.EditBody body) {
        Long memberId = MemberAcl.getLoginId();
        Map<String,Object> feeding = pigService.feeding(memberId, body);
        return AjaxResult.data(feeding);
    }

    @ApiOperation(value = "查询我的猪仔")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "getPigList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<MemberMaterialPig>> getPigList() {
        Long memberId = MemberAcl.getLoginId();
        List<MemberMaterialPig> result = pigService.getPigOneList(memberId,false);
        return AjaxResult.data(result);
    }



    @ApiOperation(value = "获取猪仔排行榜")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "getPigRanking")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigBody.ReturnBody>> getPigRanking() {
        List<PigBody.ReturnBody> pigRanking = pigService.getPigRanking();
        return AjaxResult.data(pigRanking);
    }


    @ApiOperation(value = "查询合养的猪仔")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "getPigCombineList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<MemberMaterialPig>> getPigCombineList() {
        Long memberId = MemberAcl.getLoginId();
        List<MemberMaterialPig> result = pigService.getPigOneList(memberId,true);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "设置猪仔名称")
    @PostMapping(value = "addPigName")
    @SaCheckLogin(type = MemberStp.TYPE)
    @ApiOperationSupport(order = 4)
    public AjaxResult<Map<String, String>> addPigName(@Validated PigBody.NameBody body) {
        Long memberId = MemberAcl.getLoginId();
        Map<String, String> stringStringMap = pigService.addPigName(memberId, body);
        return AjaxResult.data(stringStringMap);
    }


    @ApiOperation(value = "获取猪仔喂食记录")
    @GetMapping(value = "getFeed/{code}")
    @ApiOperationSupport(order = 5)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigResponsive.Feeding>> getFeed(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        List<PigResponsive.Feeding> feed = pigService.getFeed(code);
        return AjaxResult.data(feed);
    }

    @ApiOperation(value = "获取猪仔治疗记录")
    @GetMapping(value = "getTreatment/{code}")
    @ApiOperationSupport(order = 6)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigResponsive.Treat>> getTreatment(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        List<PigResponsive.Treat> treatment = pigService.getTreatment(code);
        return AjaxResult.data(treatment);
    }

    @ApiOperation(value = "获取猪仔服务记录")
    @GetMapping(value = "getServe/{code}")
    @ApiOperationSupport(order = 9)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigResponsive.Serve>> getServe(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        List<PigResponsive.Serve> treatment = pigService.getServe(code);
        return AjaxResult.data(treatment);
    }

    @ApiOperation(value = "获取猪仔体温运动记录")
    @GetMapping(value = "getMotion/{code}")
    @ApiOperationSupport(order = 8)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigResponsive.StepWarm>> getMotion(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        List<PigResponsive.StepWarm> motion = pigService.getMotion(code);
        return AjaxResult.data(motion);
    }

    @ApiOperation(value = "获取套餐使用情况")
    @GetMapping(value = "getEatCombo/{code}")
    @ApiOperationSupport(order = 7)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<PigResponsive.Combo> getEatCombo(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        PigResponsive.Combo eatCombo = pigService.getEatCombo(code);
        return AjaxResult.data(eatCombo);
    }

    @ApiOperation(value = "获取猪仔农管家的工单")
    @GetMapping(value = "getWorkOrder/{code}")
    @ApiOperationSupport(order = 8)
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigOrder>> getWorkOrder(@PathVariable String code) {
        Long memberId = MemberAcl.getLoginId();
        List<PigOrder> workOrder = pigService.getWorkOrder(code);
        return AjaxResult.data(workOrder);
    }

}
